package xyz.zhzby.cyzx.oss.controller;

import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import xyz.zhzby.cyzx.oss.constant.DirectoryEnum;
import xyz.zhzby.cyzx.oss.service.OssService;
import xyz.zhzby.cyzx.servicebase.domain.RestResponse;

import java.io.IOException;

/**
 * @author zby
 * @date 2021/12/15
 */
@RestController
@RequestMapping("/oss")
public class OssController {

    @Autowired
    private OssService ossService;

    @ApiOperation("上传cms模块的图片并返回图片链接")
    @PostMapping("/cms")
    public RestResponse<String> uploadOssFileCms(MultipartFile file) throws IOException {
        return ossService.uploadFileImg(file.getInputStream(), DirectoryEnum.cms.name());
    }

    @ApiOperation("上传头像图标并返回链接")
    @PostMapping("/avatar")
    public RestResponse<String> uploadOssFileAvatar(MultipartFile file) throws IOException {
        return ossService.uploadFileImg(file.getInputStream(), DirectoryEnum.avatar.name());
    }

    @ApiOperation("上传oj模块的图片并返回图片链接")
    @PostMapping("/oj")
    public RestResponse<String> uploadOssFileOj(MultipartFile file) throws IOException {
        return ossService.uploadFileImg(file.getInputStream(), DirectoryEnum.oj.name());
    }

}
